package org.junv;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class ManageCate
 */
@WebServlet("/ManageCate")
public class ManageCate extends HttpServlet {
	
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		 //控制乱码
		response.setContentType("text/html");
		response.setCharacterEncoding("utf-8");
		request.setCharacterEncoding("utf-8");
		
		PrintWriter out = response.getWriter();
		
		DBBean myBean = new DBBean();

		String cateName = request.getParameter("cateName");
		 
		//解决乱码问题，从网页到servlet...........
		 cateName  = new String(cateName.getBytes("ISO-8859-1"),"UTF8");
		
		
		System.out.println("catename:"+cateName);
		
		//cateName = new String(cateName.getBytes("UTF-8"));
		
		if(cateName==""){
			out.println("你的输入为空，请重新输入");
			return;
		}else if(cateName==null){
		    out.println("出现空指针，请重试！");
		    return;
		}
		String sql = "insert into equipCategory (equipCategoryName)values ('"
				+ cateName + "')";

		myBean.init();
		
		System.out.println(sql);
		if (myBean.executeUpdate(sql)) {

			System.out.println("成功执行");

			out.println("添加成功！");
		} else {
			System.out.println("执行失败！！");
			out.println("添加失败！");
			myBean.colse();
		}

		myBean.colse();
	}

}
